<%-- 
    Document   : insertDaftar
    Created on : 28 Nov 12, 17:56:57
    Author     : user
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <style type="text/css">
            h1 {background-color: darkgrey}
            body {background-color: gainsboro}

        </style>

    </head>
    <body>

        <h1 align="center">Konfirmasi</h1>
        <a href = "home.html">HOME</a> <br>



        <jsp:useBean id="dft" scope="session" class="model.daftar"/>
        <jsp:setProperty name="dft" property="nama" value="${param.nama}"/>
        <jsp:setProperty name="dft" property="bi" value="${param.bi}"/>
        <jsp:setProperty name="dft" property="bing" value="${param.bing}"/>
        <jsp:setProperty name="dft" property="mtk" value="${param.mtk}"/>
        <jsp:setProperty name="dft" property="ipa" value="${param.ipa}"/>
        <jsp:setProperty name="dft" property="jml" value="${param.jml}"/>


    <tr>
        <td>
            <br>Saudara/i <b><jsp:getProperty name="dft" property="nama"/></b> dengan NEM <b><jsp:getProperty name="dft" property="jml"/></b>
            sudah terdaftar sebagai calon murid baru di SMA Sanata Dharma. <br>
            Kode Test anda sebagai berikut: 

            <script language="javascript" type="text/javascript">
                function randomString() {
                    var chars = "aB1";
                    var string_length = 3;
                    var randomstring = '';
                    for (var i=0; i<string_length; i++) {
                        var rnum = Math.floor(Math.random() * chars.length);
                        randomstring += chars.substring(rnum,rnum+1);
                    }
                    document.randform.randomfield.value = randomstring;
                }
            </script>
            <form name="randform">
                <input type="button" value="Kode Test" onClick="randomString();">&nbsp;
                <input type="text" name="randomfield" value="">


            </form>
        </td>
    </tr>


    <%
        model.DataBaseConnection conn2 = new model.DataBaseConnection();
        try {
            String insert = "insert into daftar(namaLengkap, tempatLahir, tglLahir, asalSMP, alamat) "
                    + "values('" + request.getParameter("nama") + "',"
                    + "'" + request.getParameter("tempat") + "',"
                    + "'" + request.getParameter("tglLahir") + "',"
                    + "'" + request.getParameter("asal") + "',"
                    + "'" + request.getParameter("alamat") + "')";
            java.sql.Statement statement = conn2.getConnection().createStatement();
            int OK = statement.executeUpdate(insert);
            if (OK != 0) {
    %>
    <strong>UPDATE SUKSES!!!</strong>
    <br><br>
    <%try {
            String query = "select * from daftar";
            java.sql.ResultSet result = statement.executeQuery(query);
    %>


    <%
            statement.close();
        } catch (Exception ex) {
            System.out.println("message: " + ex.getMessage());
              }
          } else {%>
    <strong>UPDATE GAGAL!!!</strong>
    <%}
            statement.close();
        } catch (Exception ex) {
            out.println("message: " + ex.getMessage());
        }
    %>
    <a href="Daftar.jsp"> Input Again..!!!</a>
    <input type="submit" value="Balik">
</form>

</body>
</html>
